﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace ElegxosMiFisikwnProswpwn
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }


        void cl_rgWsBasStoixNCompleted(object sender, GSISServiceReference.rgWsBasStoixEpitCompletedEventArgs e)
        {
            SystemTray.SetProgressIndicator(this, null);

            if (e.Error == null)
            {
                if (e.pErrorRec_out.errorDescr != null)
                    MessageBox.Show(e.pErrorRec_out.errorDescr);
                else
                    LayoutRoot.DataContext = e.pBasStoixEpitRec_out;
            }
            else
            {
                MessageBox.Show("Σημειώθηκε σφάλμα. Παρακαλώ ελέγξτε την σύνδεση του δικτύου σας ή προσπαθήστε αργότερα");
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if(!Utilities.ValidateAFM(textBox1.Text.Trim()))
            {
                MessageBox.Show("Το ΑΦΜ δεν είναι έγκυρο");
                return;
            }

            GSISServiceReference.RgWsBasStoixNClient cl = new GSISServiceReference.RgWsBasStoixNClient();
            cl.rgWsBasStoixEpitCompleted += new EventHandler<GSISServiceReference.rgWsBasStoixEpitCompletedEventArgs>(cl_rgWsBasStoixNCompleted);

            ProgressIndicator progress = new ProgressIndicator() {
                IsVisible = true,
                IsIndeterminate = true,
                Text = "Παρακαλώ περιμένετε..."
            };
            SystemTray.SetProgressIndicator(this, progress);
            cl.rgWsBasStoixEpitAsync(textBox1.Text.Trim(), new GSISServiceReference.RgWsBasStoixEpitRtUser(), 0, new GSISServiceReference.GenWsErrorRtUser());
            
        }

        private void ApplicationBarMenuItem_Click(object sender, System.EventArgs e)
        {
        	// TODO: Add event handler implementation here.
			NavigationService.Navigate(new Uri("/About.xaml", UriKind.Relative));
        }

       
    }
}